home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src / htsparse.h < prev    next >
C/C++ Source or Header  |  2006-08-15  |  6KB  |  191 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: htsparse.h parser                                      */
  34. /*       html/javascript/css parser                             */
  35. /*       and other parser routines                              */
  36. /* Author: Xavier Roche                                         */
  37. /* ------------------------------------------------------------ */
  38.  
  39. #include "htsglobal.h"
  40.  
  41. /* Forward definitions */
  42. #ifndef HTS_DEF_FWSTRUCT_htsblk
  43. #define HTS_DEF_FWSTRUCT_htsblk
  44. typedef struct htsblk htsblk;
  45. #endif
  46. #ifndef HTS_DEF_FWSTRUCT_robots_wizard
  47. #define HTS_DEF_FWSTRUCT_robots_wizard
  48. typedef struct robots_wizard robots_wizard;
  49. #endif
  50. #ifndef HTS_DEF_FWSTRUCT_hash_struct
  51. #define HTS_DEF_FWSTRUCT_hash_struct
  52. typedef struct hash_struct hash_struct;
  53. #endif
  54.  
  55. #ifndef HTS_DEF_FWSTRUCT_htsmoduleStructExtended
  56. #define HTS_DEF_FWSTRUCT_htsmoduleStructExtended
  57. typedef struct htsmoduleStructExtended htsmoduleStructExtended;
  58. #endif
  59. struct htsmoduleStructExtended {
  60.   /* Main object */
  61.   htsblk* r_;
  62.  
  63.   /* Error handling */
  64.   int* error_;
  65.   int* exit_xh_;
  66.   int* store_errpage_;
  67.  
  68.   /* Structural */
  69.   int* filptr_;
  70.   char*** filters_;
  71.   robots_wizard* robots_;
  72.   hash_struct* hash_;
  73.   int* lien_max_;
  74.  
  75.   /* Base & codebase */
  76.   char* base;
  77.   char* codebase;
  78.  
  79.   /* Index */
  80.   int* makeindex_done_;
  81.   FILE** makeindex_fp_;
  82.   int* makeindex_links_;
  83.   char* makeindex_firstlink_;
  84.  
  85.   /* Html templates */
  86.   char *template_header_;
  87.   char *template_body_;
  88.   char *template_footer_;
  89.  
  90.   /* Specific to downloads */
  91.   LLint* stat_fragment_;
  92.   TStamp makestat_time;
  93.   FILE* makestat_fp;
  94.   LLint* makestat_total_;
  95.   int* makestat_lnk_;
  96.   FILE* maketrack_fp;
  97.  
  98.   /* Function-dependant */
  99.   char* loc_;
  100.   TStamp* last_info_shell_;
  101.   int* info_shell_;
  102.  
  103. };
  104.  
  105.  
  106. /* Library internal definictions */
  107. #ifdef HTS_INTERNAL_BYTECODE
  108.  
  109. /*
  110.   Main parser, attempt to scan links inside the html/css/js file
  111.   Parameters: The public module structure, and the private module variables
  112. */
  113. int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre);
  114.  
  115. /*
  116.   Check for 301,302.. errors ("moved") and handle them; re-isuue requests, make
  117.   rediretc file, handle filters considerations..
  118.   Parameters: The public module structure, and the private module variables
  119.   Returns 0 upon success
  120. */
  121. int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre);
  122.  
  123. /*
  124.   Get the next file on the queue, waiting for it, handling other files in background..
  125.   Parameters: The public module structure, and the private module variables
  126.   Returns 0 upon success
  127. */
  128. int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended* stre);
  129.  
  130. /*
  131.   Wair for (adr, fil, save) to be started, that is, 
  132.   to be ready for naming, having its header MIME type
  133.   If the final URL is to be forbidden, sets 'forbidden_url' to the corresponding value
  134. */
  135. int hts_wait_delayed(htsmoduleStruct* str, 
  136.                      char* adr, char* fil, char* save, 
  137.                      char* parent_adr, char* parent_fil,
  138.                      char* former_adr, char* former_fil, 
  139.                      int* forbidden_url);
  140.  
  141.  
  142. /* Context state */
  143.  
  144. #define ENGINE_LOAD_CONTEXT_BASE() \
  145.   lien_url** const liens HTS_UNUSED = (lien_url**) str->liens; \
  146.   httrackp* const opt HTS_UNUSED = (httrackp*) str->opt; \
  147.   struct_back* const sback HTS_UNUSED = (struct_back*) str->sback; \
  148.   lien_back* const back HTS_UNUSED = sback->lnk; \
  149.   const int back_max HTS_UNUSED = sback->count; \
  150.   cache_back* const cache HTS_UNUSED = (cache_back*) str->cache; \
  151.   hash_struct* const hashptr HTS_UNUSED = (hash_struct*) str->hashptr; \
  152.   const int numero_passe HTS_UNUSED = str->numero_passe; \
  153.   const int add_tab_alloc HTS_UNUSED = str->add_tab_alloc; \
  154.   /* */ \
  155.   int lien_tot HTS_UNUSED = *str->lien_tot_; \
  156.   int ptr HTS_UNUSED = *str->ptr_; \
  157.   size_t lien_size HTS_UNUSED = *str->lien_size_; \
  158.   char* lien_buffer HTS_UNUSED = *str->lien_buffer_
  159.  
  160. #define ENGINE_SAVE_CONTEXT_BASE() \
  161.   /* Apply changes */ \
  162.   * str->lien_tot_ = lien_tot; \
  163.   * str->ptr_ = ptr; \
  164.   * str->lien_size_ = lien_size; \
  165.   * str->lien_buffer_ = lien_buffer
  166.  
  167. #define WAIT_FOR_AVAILABLE_SOCKET() do { \
  168.   int prev = opt->state._hts_in_html_parsing; \
  169.   while(back_pluggable_sockets_strict(sback, opt) <= 0) { \
  170.     opt->state._hts_in_html_parsing = 6; \
  171.     /* Wait .. */ \
  172.     back_wait(sback,opt,cache,0); \
  173.     /* Transfer rate */ \
  174.     engine_stats(); \
  175.     /* Refresh various stats */ \
  176.     HTS_STAT.stat_nsocket=back_nsoc(sback); \
  177.     HTS_STAT.stat_errors=fspc(opt,NULL,"error"); \
  178.     HTS_STAT.stat_warnings=fspc(opt,NULL,"warning"); \
  179.     HTS_STAT.stat_infos=fspc(opt,NULL,"info"); \
  180.     HTS_STAT.nbk=backlinks_done(sback,liens,lien_tot,ptr); \
  181.     HTS_STAT.nb=back_transfered(HTS_STAT.stat_bytes,sback); \
  182.     /* Check */ \
  183.     if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, -1,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) { \
  184.       return -1; \
  185.     } \
  186.   } \
  187.   opt->state._hts_in_html_parsing = prev; \
  188. } while(0)
  189.  
  190. #endif
  191.